package com.hy.study.reduce;

import com.hy.study.bean.OrderBean;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author huyong 这里要获取最大的那个，默认写第一个
 * @date 2024 年 02 月 05 日 17:46: 58
 */
public class OrderReducer extends Reducer<OrderBean, NullWritable, OrderBean, NullWritable> {
    @Override
    protected void reduce(OrderBean key, Iterable<NullWritable> values, Reducer<OrderBean, NullWritable, OrderBean, NullWritable>.Context context) throws IOException, InterruptedException {
        // 输出第一个
        //  context.write(key, NullWritable.get());
        //输出前两个
        int count=0;
       for(NullWritable nullWritable:values){
            if(count<2){
                context.write(key, NullWritable.get());
            }
            count++;
       }

    }
}
